package com.ics.atable.chat.controller;

import com.ics.atable.chat.config.ChatClientServiceFactory;
import com.ics.atable.chat.model.dto.IntentExtract;
import com.ics.atable.chat.prompt.PromptConstant;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.checkerframework.checker.units.qual.A;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

/**
 * 意图识别
 *
 * @author haohongbin
 */
@Tag(name = "意图识别")
@RestController
@RequestMapping("/intent")
public class IntentController {

    @Autowired
    private ChatClientServiceFactory chatClientServiceFactory;

    @PostMapping("/recognize")
    public IntentExtract recognize(String message, String sessionId) {

        String systemPrompt = PromptConstant.getIntentPromptTemplate();
        return chatClientServiceFactory.getOrCreateIntentChatClient()
                .prompt(message)
                .system(systemPrompt)
                .advisors(spec -> spec.param(CONVERSATION_ID, sessionId))
                .call()
                .entity(IntentExtract.class);
    }
}
